﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 坦克大战
{
    enum Dirction
    {
        Up, 
        Down, 
        Left, 
        Right
    }
    internal class Movingthing:GameObject
    {
        public Bitmap BitmapUp { get; set; }
        public Bitmap BitmapDown { get; set; }
        public Bitmap BitmapLeft { get; set; }
        public Bitmap BitmapRight { get; set; }
        public int Speed { get; set; }
        private Object _lock = new Object();    
        public Dirction dir;
        public Dirction Dir { get { return dir; } 
        set {
                dir=value;
                Bitmap bmp = null;
                
                switch (dir)
                {
                    case Dirction.Up:
                        bmp= BitmapUp;
                        break;
                    case Dirction.Down:
                        bmp= BitmapDown;
                        break;
                    case Dirction.Left:
                        bmp= BitmapLeft;
                        break;
                    case Dirction.Right:
                        bmp= BitmapRight;
                        break;
                    default:
                        bmp = BitmapUp;
                        break;


                }
                lock (_lock)
                {
                    Width = bmp.Width;
                    Height = bmp.Height;
                }
                
            } 
        }

        public override void DrawSelf()
        {
            lock(_lock)
            {
                base.DrawSelf();
            }
            
        }

        protected override Image GetImage()
        {
            Bitmap bitmap = null;   
            switch (Dir)
            {
                case Dirction.Up:
                    bitmap=BitmapUp;
                    break;
                case Dirction.Down:
                    bitmap = BitmapDown;
                    break;
                case Dirction.Left:
                    bitmap = BitmapLeft;
                    break;
                case Dirction.Right:
                    bitmap = BitmapRight;
                    break;
                default:
                    bitmap = BitmapUp;
                    break;


            }

            bitmap.MakeTransparent(Color.Black);
            return bitmap;

        }


    }
}
